unit UretimDurumunuGor;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, ADODB, Grids, Wwdbigrd, Wwdbgrid, StdCtrls, Buttons,
  ExtCtrls, Mask, wwdbedit, Wwdotdot, Wwdbcomb;

type
  TUretimDurumunuGorF = class(TForm)
    SiparisDurumunuGorQ: TADOQuery;
    SiparisDurumunuGorQS: TDataSource;
    wwDBGrid1: TwwDBGrid;
    Panel1: TPanel;
    BitBtn1: TBitBtn;
    emirnol: TLabel;
    emirtarihl: TLabel;
    emirnok: TStaticText;
    emirtarihk: TStaticText;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    SiparisHarId: Integer;
    Tumu: boolean;
    { Public declarations }
  end;

var
  UretimDurumunuGorF: TUretimDurumunuGorF;

implementation

uses data, ana1, U_COMMONLOGO, DateUtils;

{$R *.dfm}

procedure TUretimDurumunuGorF.FormClose(Sender: TObject; var Action:
  TCloseAction);
begin
  Action := CaFree;
  UretimDurumunuGorF := nil;
end;

procedure TUretimDurumunuGorF.FormShow(Sender: TObject);
var
  Year: string;
begin
  Year := IntToStr(YearOf(SadeceTarih));

  if tumu = False then
  begin
    SiparisDurumunuGorQ.Close;
    SiparisDurumunuGorQ.sql.text := 'select makinano,CONVERT(varchar(16),tarih,104) as bastarih,CONVERT(varchar(5),tarih,114) as hazirlama,CONVERT(varchar(5),montajtarih,114) as montaj,CONVERT(varchar(5),testt,114)  as test,';
    SiparisDurumunuGorQ.sql.add('CONVERT(varchar(5),paktar,114)  as paket,cikis=(select dbo.getcarikodu(carikod) from fatura where fatura.bilisno=(select bilisnocik from fatharhar where fatharhar.serinos=uretim.makinano)) from uretim');
    SiparisDurumunuGorQ.sql.add('where uretimno in (SELECT aktarilanuremrino FROM unity_emirlistesi where siparisharid=' + inttostr(SiparisHarid) + ')');
//    SiparisDurumunuGorQ.sql.add('where Year(Tarih)=' + Year + ' and uretimno in (SELECT aktarilanuremrino FROM unity_emirlistesi where siparisharid=' + inttostr(SiparisHarid) + ')');
    SiparisDurumunuGorQ.sql.add('order by cikis');
    SiparisDurumunuGorQ.Open;

    dm.gecici.Close;
    dm.gecici.sql.text := 'select emirno,CONVERT(varchar(10),tarih,104) as tarih from uremri where emirno=(SELECT top 1 aktarilanuremrino FROM unity_emirlistesi where siparisharid=' + inttostr(SiparisHarid) + ')';
    dm.gecici.Open;

    if dm.gecici.recordcount = 1 then
    begin
      emirnok.Caption := ' ' + inttostr(dm.gecici.fieldbyname('emirno').asinteger);
      emirtarihk.Caption := ' ' + dm.gecici.fieldbyname('tarih').value;
    end;
  end
  else
  begin
    SiparisDurumunuGorQ.Close;
    SiparisDurumunuGorQ.sql.text := 'select makinano,CONVERT(varchar(16),tarih,104) as bastarih,CONVERT(varchar(5),tarih,114) as hazirlama,CONVERT(varchar(5),montajtarih,114) as montaj,CONVERT(varchar(5),testt,114)  as test,';
    SiparisDurumunuGorQ.sql.add('CONVERT(varchar(5),paktar,114)  as paket,cikis=(select dbo.getcarikodu(carikod) from fatura where fatura.bilisno=(select bilisnocik from fatharhar where fatharhar.serinos=uretim.makinano)) from uretim');
    SiparisDurumunuGorQ.sql.add('where uretimno in (SELECT aktarilanuremrino FROM unity_emirlistesi where siparisharid in (select id from unity_siparishar_2006 where siparisid=' + inttostr(SiparisHarid) + '))');
//    SiparisDurumunuGorQ.sql.add('where  Year(Tarih)=' + Year + ' and uretimno in (SELECT aktarilanuremrino FROM unity_emirlistesi where siparisharid in (select id from unity_siparishar_2006 where siparisid=' + inttostr(SiparisHarid) + '))');
    SiparisDurumunuGorQ.sql.add('order by cikis');
    SiparisDurumunuGorQ.Open;

    dm.gecici.Close;
    dm.gecici.sql.text := 'select emirno,CONVERT(varchar(10),tarih,104) as tarih from uremri where emirno=(SELECT top 1 aktarilanuremrino FROM unity_emirlistesi where siparisharid in (select id from unity_siparishar_2006 where siparisid=' + inttostr(SiparisHarid) + '))';
    dm.gecici.Open;

    if dm.gecici.recordcount = 1 then
    begin
      emirnok.Caption := ' ' + inttostr(dm.gecici.fieldbyname('emirno').asinteger);
      emirtarihk.Caption := ' ' + dm.gecici.fieldbyname('tarih').value;
    end;
  end;
  anaform.CreateExport(Self);
end;

procedure TUretimDurumunuGorF.BitBtn1Click(Sender: TObject);
begin
  close;
end;

procedure TUretimDurumunuGorF.FormKeyPress(Sender: TObject; var Key: Char);
begin
  if key = #27 then close;
end;

end.

